package redis.inaction.xx.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

//内部框架类
public class SendMsgUtil {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static void sendJsonMessage(HttpServletResponse response, CommonResponse fail) throws IOException {
        response.setContentType("application/json");
        try(OutputStreamWriter ow = new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8)){
            ow.write(objectMapper.writeValueAsString(fail));
            ow.flush();
        }
    }
}
